package com.shiwaixiangcun.customer.adapter

import android.widget.RelativeLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.shiwaixiangcun.customer.R
import com.shiwaixiangcun.customer.glide.ImageDisplayUtil
import com.shiwaixiangcun.customer.module.homeservice.ToHomeServiceType
import com.shiwaixiangcun.customer.utils.DisplayUtil
import com.shiwaixiangcun.customer.widget.RoundImageView

/**
 * Author   Administrator
 * Date     2018/1/17
 * Desc     eg
 *
 * @author Administrator
 */

class AdapterHouseCategory(data: List<ToHomeServiceType>?) : BaseQuickAdapter<ToHomeServiceType, BaseViewHolder>(R.layout.item_layout_service_category, data) {

    override fun convert(helper: BaseViewHolder, item: ToHomeServiceType) {

        //动态测量item数据
        val dm = mContext.resources.displayMetrics
        val width = dm.widthPixels
        val viewWith = (width - DisplayUtil.dip2px(mContext, 20f) * 2) / 2
        val viewHeight = viewWith / 2
        val position = helper.adapterPosition
        var isLeft = false
        isLeft = position % 2 == 0
        val imageView = helper.getView<RoundImageView>(R.id.iv_tool)
        val layoutParams = imageView.layoutParams as RelativeLayout.LayoutParams
        if (isLeft) {
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
            layoutParams.addRule(RelativeLayout.CENTER_VERTICAL)
        } else {
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
            layoutParams.addRule(RelativeLayout.CENTER_VERTICAL)

        }
        layoutParams.width = viewWith
        layoutParams.height = viewHeight
        imageView.layoutParams = layoutParams


//        ImageDisplayUtil.showImageView(mContext, item.imagePath, imageView)


        ImageDisplayUtil.showImageView(mContext, item.thumbIcon, imageView)
//        Glide.with(mContext).load(item.thumbIcon).into(iv)
    }
}
